package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.Observer;

import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableModel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class OverzichtPanel extends javax.swing.JPanel implements ListSelectionListener{
	private JScrollPane jScrollPaneOvezicht;
	private JLabel lblTitel;
	private JTable jTableOverzicht;
    private Observer observer;

    
    
    public OverzichtPanel(TableModel jTableOverzichtModel, String titel) {
    		
    	super();
		initGUI(jTableOverzichtModel, titel);
	}
	
	private void initGUI(TableModel jTableOverzichtModel, String titel) {
		try {
			setPreferredSize(new Dimension(400, 300));
			BorderLayout thisLayout = new BorderLayout();
			this.setLayout(thisLayout);
			
			lblTitel = new JLabel();
			this.add(lblTitel, BorderLayout.NORTH);
		
			lblTitel.setText(titel);
			
			observer = (Observer) jTableOverzichtModel;
			jTableOverzicht = new JTable();
			jTableOverzicht.setModel(jTableOverzichtModel);
			jTableOverzicht.setSelectionMode(
                    ListSelectionModel.SINGLE_SELECTION);
			jTableOverzicht.getSelectionModel().addListSelectionListener(this);
			jScrollPaneOvezicht = new JScrollPane(jTableOverzicht);
			jScrollPaneOvezicht.createVerticalScrollBar().setVisible(true);
			this.add(jScrollPaneOvezicht, BorderLayout.CENTER);
			jScrollPaneOvezicht.setPreferredSize(new java.awt.Dimension(385, 284));
			jScrollPaneOvezicht.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void valueChanged(ListSelectionEvent event) {
		//TODO
		
		if(event.getValueIsAdjusting())
		{
			return;
		}
		observer.update(null, jTableOverzicht.getSelectedRow()); // dit doen we omdat jtable 2 events stuurt ( muis en pijltjes op het toetsenbord)
		// dus dan wordt het 2 keer uitgevoerd, vandaar deze if. Deze zorgt ervoor dat er maar 1 event wordt uitgevoerd.
		
	}




}
